package com.qf.homework.dao.impl;

import com.qf.homework.controller.entity.Category;
import com.qf.homework.dao.CategoryDao;
import com.qf.homework.utils.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public List<Category> getCategoryList(int currentPage, int size) throws SQLException {
        Connection connection = DBManager.getConnection();
        System.out.println(connection);
        String sql="select *from cate_tb limit ?,?";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setInt(1,currentPage);
        ps.setInt(2,size);
        ResultSet resultSet = ps.executeQuery();
        List<Category> list=new LinkedList<>();
        while (resultSet.next()) {
            int cateId = resultSet.getInt(1);
            String name = resultSet.getString(2);
            int isDelete = resultSet.getInt(3);
            list.add(new Category(cateId,name,isDelete));
        }
        return list;
    }
}
